﻿using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace PolePosition.v3.Desktop.Editors
{
    public partial class EditDistributionInspectionVisit : DialogBase, IDialogBase
    {
        public EditDistributionInspectionVisit(bool IsEdit, EntityLibrary.VendorDistributionPoleEntity data)
        {
            InitializeComponent();


            m_IsEdit = IsEdit;
            Data = data;

            if (IsEdit)
                base.buttonXOk.Text = "Save";
            else
                base.buttonXOk.Text = "Ok";

            if (data.VendorDistributionMeterCollection == null || data.VendorDistributionMeterCollection.Count == 0)
            {
                buttonItemMeter.Enabled = false;
            }
            else
            {
                meter1.Dock = DockStyle.Fill;
                meter1.EditAllowed = IsEdit;
                meter1.Data = data.VendorDistributionMeterCollection[0];
                buttonItemMeter.Enabled = true;
            }

            if (data.VendorDistributionTransformerCollection == null || data.VendorDistributionTransformerCollection.Count == 0)
            {
                buttonItemTransformer.Enabled = false;
            }
            else
            {
                transformer1.Dock = DockStyle.Fill;
                transformer1.EditAllowed = IsEdit;
                transformer1.Data = data.VendorDistributionTransformerCollection[0];
                buttonItemTransformer.Enabled = true;
            }

            if (data.VendorDistributionSectionalizerCollection == null || data.VendorDistributionSectionalizerCollection.Count == 0)
            {
                buttonItemSectionalizer.Enabled = false;
            }
            else
            {
                sectionalizer1.Dock = DockStyle.Fill;
                sectionalizer1.EditAllowed = IsEdit;
                sectionalizer1.Data = data.VendorDistributionSectionalizerCollection[0];
                buttonItemSectionalizer.Enabled = true;
            }

            if (data.VendorDistributionRecloserCollection == null || data.VendorDistributionRecloserCollection.Count == 0)
            {
                buttonItemRecloser.Enabled = false;
            }
            else
            {
                recloser1.Dock = DockStyle.Fill;
                recloser1.EditAllowed = IsEdit;
                recloser1.Data = data.VendorDistributionRecloserCollection[0];
                buttonItemRecloser.Enabled = true;
            }

            images1.Dock = DockStyle.Fill;
            images1.LoadImages(data.Vendor_Distribution_Poles_PoleId.Value, PolePosition.v3.Common.Enumerations.DataTypes.ProjectsDistributionInspection);
            transformer1.Dock = DockStyle.Fill;
            sectionalizer1.Dock = DockStyle.Fill;
            recloser1.Dock = DockStyle.Fill;
            distributionPole1.Dock = DockStyle.Fill;
            distributionPole1.EditAllowed = IsEdit;
            distributionPole1.Data = data;
            inspection1.Dock = DockStyle.Fill;
            inspection1.EditAllowed = IsEdit;
            inspection1.Data = data;
            inspection1.BringToFront();
        }

        private bool m_IsEdit;

        public EntityLibrary.VendorDistributionPoleEntity Data { get; set; }

        #region Asynch Processing (Implements IDialogBase)

        //to start the asynch background worker call - base.StartAsynchWork()

        public override void DoAsynchWork(DoWorkEventArgs e)
        {

            //do whatever needs to be done asynch here (BackgroudWorker_DoWork)


        }

        public override void AsychWorkComplete(object sender, RunWorkerCompletedEventArgs e)
        {
            base.AsychWorkComplete(sender, e);
            //do whatever needs to be done after asynch work complete (BackgroudWorker_RunWorkerCompleted)


        }


        #endregion

        private void buttonItemInspection_Click(object sender, EventArgs e)
        {
            inspection1.BringToFront();
        }

        private void buttonItemDistribution_Click(object sender, EventArgs e)
        {
            distributionPole1.BringToFront();
        }

        private void buttonItemImages_Click(object sender, EventArgs e)
        {
            images1.BringToFront();
        }

        private void buttonItemMeter_Click(object sender, EventArgs e)
        {
            meter1.BringToFront();
        }

        private void buttonItemTransformer_Click(object sender, EventArgs e)
        {
            transformer1.BringToFront();
        }

        private void buttonSectionalizer_Click(object sender, EventArgs e)
        {
            sectionalizer1.BringToFront();
        }

        private void buttonRecloser_Click(object sender, EventArgs e)
        {
            recloser1.BringToFront();
        }

    }
}
